package parser

import (
	"engine"
	"regexp"
	"strings"
)

var ProdDirsReg = regexp.MustCompile(`<a href="([0-9A-Z]{4}/)">([^<]*)</a>`)

func ParseGuidePage(content []byte, url string) engine.ParserResult {
	result := engine.ParserResult{}
	submatches := ProdDirsReg.FindAllSubmatch(content, -1)
	for _, m := range submatches {
		prodDir := string(m[1])
		itemUrl := url + prodDir
		result.Items = append(result.Items, prodDir)
		result.Requests = append(result.Requests, engine.Request{
			CurURL: itemUrl,
			RefURL: url,
			ParserFunc: func(c []byte) engine.ParserResult {
				return ParseProductConfig(c, itemUrl, strings.Replace(prodDir, "/", "", -1))
			},
		})
		//limit --
		//if limit == 0 {
		//	break
		//}
	}
	return result
}
